package DaEr2_1;

import java.util.Random;
import java.util.Scanner;

public class CaiShu {
    public static void main(String[] args) {
        Random random = new Random();
        int guessnum = random.nextInt(10)+1;
        int flag=0;
        while (flag<3) {//for(flag=0;flag<3;flag++;)
            System.out.println("请猜数：");
            Scanner scanner = new Scanner(System.in);
            int usernum = scanner.nextInt();
            if (guessnum > usernum) {
                System.out.println("猜小了");
                flag++;
            } else if (guessnum < usernum) {
                System.out.println("猜大了");flag++;
            } else if (guessnum == usernum) {
                System.out.println("恭喜你 猜对了");
                break;
            }
            if (flag<3) {
                System.out.println("您还有" + (3-flag) + "次机会");
            }else {
                System.out.println("您的机会用完了");
            }
        }
    }
}
